package com.waar.kickball.model;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * @author Craig McIlwee
 * Copyright Lance + Craig 2013
 */
@Entity
@Table(name = "game")
public class Game extends KickballEntity {

	@ManyToOne(cascade = CascadeType.PERSIST)
	@JoinColumn(name = "home_team_id", nullable = false)
	private Team home;
	@ManyToOne(cascade = CascadeType.PERSIST)
	@JoinColumn(name = "away_team_id", nullable = false)
	private Team away;
	@OneToMany(cascade = CascadeType.PERSIST)
	@JoinColumn(name = "game_id")
	private Set<Inning> innings;
	
	Game() { }

	/**
	 * @param home the home team
	 * @param away the away team
	 * @param innings that make up the game
	 */
	public Game(Team home, Team away, Set<Inning> innings) {
		this.home = home;
		this.away = away;
		this.innings = innings;
	}

	/**
	 * @return the home team, fields first
	 */
	public Team getHome() {
		return home;
	}

	/**
	 * @return the away team, kicks first
	 */
	public Team getAway() {
		return away;
	}

	/**
	 * @return the innings in this game
	 */
	public Set<Inning> getInnings() {
		return innings;
	}
	
}
